import Vue from 'vue'
import VueRouter from 'vue-router'
import { routers } from './router'
import { getToken } from '@/utils/auth'
Vue.use(VueRouter)

// 路由配置
const RouterConfig = {
    // mode: 'hash',
    routes: routers
}

export const router = new VueRouter(RouterConfig)

router.beforeEach((to, from, next) => {
    if ((to.path != '/login') && (!getToken() || getToken() == 'undefined')) {
        next({
            path: '/login'
            // query: { redirect: to.fullPath }
        })
    } else {
        next()
    }
})

router.afterEach(to => {
    window.scrollTo(0, 0)
})
